import axios from 'axios'
import qs from 'qs'
import configFile from './config'

export default class Wx {
    constructor() {
        this.appID = 'wx038bb34d988ffe33';
        this.appsecret = '09ae9ea1dcf44c17f6cb2cf7bc6dd47e';
    }
    // 微信的权限认证
    checkJsSdkMy() {
        let rb = new Promise((reslove, reject) => {
            var baseurl = window.location.href;
            let url = baseurl.split('#');
            let postData = qs.stringify({
                baseurl: url[0]
            });
            axios.post('http://ocn.wechat.thinghigh.cn/index.php/api/clockPunch/jssdk', postData).then(r => {
                let arr = r.data
                wx.config({
                    debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印
                    appId: arr.signPackage.appId, // 必填，公众号的唯一标识
                    timestamp: arr.signPackage.timestamp, // 必填，生成签名的时间戳
                    nonceStr: arr.signPackage.nonceStr, // 必填，生成签名的随机串
                    signature: arr.signPackage.signature, // 必填，签名，见附录1
                    jsApiList: [
                        "chooseImage",
                        "getLocalImgData",
                        "uploadImage",
                        "previewImage",
                        "downloadImage",
                        "startRecord",
                        "stopVoice",
                        "getLocation"
                    ]
                });
            })
        })
        return rb
    }
    // 微信的权限认证
    checkJsSdkMyNode() {
        let rb = new Promise((reslove, reject) => {
            var baseurl = window.location.href;
            let url = baseurl.split('#');
            axios.post('http://bphome.s1.natapp.cc/api/v1/wx/sign?', {
                url: encodeURI(url[0])
            }).then(r => {
                let arr = r.data
                console.log(arr);
                wx.config({
                    debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印
                    appId: arr.appId, // 必填，公众号的唯一标识
                    timestamp: arr.timestamp, // 必填，生成签名的时间戳
                    nonceStr: arr.nonceStr, // 必填，生成签名的随机串
                    signature: arr.signature, // 必填，签名，见附录1
                    jsApiList: [
                        "chooseImage",
                        "getLocalImgData",
                        "uploadImage",
                        "previewImage",
                        "downloadImage",
                        "startRecord",
                        "stopVoice",
                        "getLocation"
                    ]
                });
            })
        })
        return rb
    }
    // 微信的权限认证 后端
    checkJsSdk() {
        let rb = new Promise((reslove, reject) => {
            const res = new configFile()
            var baseurl = window.location.href;
            let url = baseurl.split('#');
            let postData = qs.stringify({
                url: url[0]
            });
            // https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxd1a58b168f23db27&redirect_uri=http%3a%2f%2fthinghigh.cn%2fwechat%2fhekou&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect
            axios.post(res.interport.host + '/mobile/mobileWf.shtml?act=getConfig', postData).then(r => {
                let arr = r.data;
                wx.config({
                    debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印
                    appId: arr.appId, // 必填，公众号的唯一标识
                    timestamp: arr.timestamp, // 必填，生成签名的时间戳
                    nonceStr: arr.nonceStr, // 必填，生成签名的随机串
                    signature: arr.signature, // 必填，签名，见附录1
                    jsApiList: [
                        "chooseImage",
                        "getLocalImgData",
                        "uploadImage",
                        "previewImage",
                        "downloadImage",
                        "startRecord",
                        "stopVoice",
                        "getLocation"
                    ]
                });
            })

        })
        return rb
    }

}